DELETE FROM [20121216-TRACE]
GO

SELECT *
FROM [20121216-TRACE]
ORDER BY DURATION DESC
GO

SELECT
	CAST(TEXTDATA AS VARCHAR(50)) AS CONSULTA,
	SUM(DURATION) / 1000000.0 AS DURACION_TOTAL,
	AVG(DURATION) / 1000000.0 AS DURACION_PROMEDIO,
	COUNT(*) AS NUMERO_EJECUCIONES
FROM
	[20121216-TRACE]
WHERE
	TEXTDATA IS NOT NULL
	AND ENDTIME IS NOT NULL
GROUP BY
	CAST(TEXTDATA AS VARCHAR(50))
ORDER BY
	AVG(DURATION) DESC
